<template>
  <div>
    <form>
      商品名称<input type="text" v-model="form11.name" /> 商品价格
      <input type="text" v-model.number="form11.price" /> 商品数量<input
        type="text"
        v-model.number="form11.num"
      />
      <button @click="addInput">添加</button>
    </form>
    <table border="1" width="700" style="border-collapse: collapse">
      <caption>
        购物车
      </caption>
      <thead>
        <tr>
          <th>
            <input type="checkbox" v-model="isAll" @click="isture" />
            <span>全选</span>
          </th>
          <th>名称</th>
          <th>价格</th>
          <th>数量</th>
          <th>总价</th>
          <th>操作</th>
        </tr>
      </thead>
      <my-table></my-table>
      <tfoot>
        <tr>
          <td>合计:</td>
          <td colspan="5">{{ count }}</td>
        </tr>
      </tfoot>
    </table>
  </div>
</template>

<script>
import MyTable from './components/MyTable.vue'
import { mapMutations, mapGetters, mapState } from 'vuex'

export default {
  components: { MyTable },

  data () {
    return {
      form11: {
        name: '',
        price: 0,
        num: 0,
        checked: false
      }
    }
  },
  methods: {
    ...mapMutations(['inputAdd', 'editInput']),
    addInput () {
      this.inputAdd(this.form11)
      this.form11 = {
        name: '',
        price: 0,
        num: 0,
        checked: false
      }
    },
    isture () {
      // console.log(this.isAll)
      this.editInput(this.isAll)
    }
  },
  computed: {
    ...mapGetters(['count']),
    ...mapState(['goodList']),
    isAll: {
      get () {
        return this.goodList.every((item) => item.checked)
      },
      set (val) {}
    }
  }
}
</script>

<style></style>
